package o;

import android.os.Handler;
import android.os.Looper;
import com.google.android.exoplayer2.offline.DownloadService;
import java.util.concurrent.atomic.AtomicInteger;

public class cfx {
    private static cfx ˋ;
    private boolean ˊ;
    private final AtomicInteger ˎ = new AtomicInteger();
    private long ˏ;
    private Handler ॱ = new Handler(Looper.getMainLooper());
    private int ॱॱ = ccz.ॱ();
    private Runnable ᐝ = new Runnable(this) {
        final /* synthetic */ cfx ˋ;

        {
            this.ˋ = r1;
        }

        public void run() {
            this.ˋ.ʻ();
            Logger.ˎ("SidProvider", "sid is changed: " + cfx.ˊ());
            ॱ();
            this.ˋ.ˋ();
        }

        private void ॱ() {
            if (cfx.ॱ().ˊ) {
                cfx.ॱ().ॱ("thirty_minutes", this.ˋ.ॱॱ);
            }
        }
    };

    private void ॱ(String str, int i) {
        if (diu.ˊ().ˎ()) {
            cvt o_dgt = new dgt(str);
            o_dgt.setServiceType_(i);
            cfw.ˎ(o_dgt, new dgo("SidProvider"));
            return;
        }
        Logger.ˏ("SidProvider", "Protocol is not agreed, can not do daily report request");
    }

    private cfx() {
    }

    private static synchronized cfx ॱ() {
        cfx o_cfx;
        synchronized (cfx.class) {
            if (ˋ == null) {
                ˋ = new cfx();
            }
            o_cfx = ˋ;
        }
        return o_cfx;
    }

    public static long ˊ() {
        return ॱ().ˏ;
    }

    public static void ˊ(int i) {
        ॱ().ˏ(i);
        if (1 == ॱ().ˎ.incrementAndGet()) {
            ॱ().ˊ = true;
            ॱ().ʻ();
            ॱ().ˋ();
            Logger.ˎ("SidProvider", "createSidGenerator, the sid : " + ˊ());
        }
    }

    public static void ˎ(int i) {
        ॱ().ˏ(i);
        if (!ॱ().ˊ) {
            ॱ().ˊ = true;
            ॱ().ॱॱ();
            Logger.ˎ("SidProvider", "generateSidForeground, the sid : " + ˊ());
            ॱ().ॱ(DownloadService.KEY_FOREGROUND, i);
        }
    }

    public static void ॱ(int i, boolean z) {
        ॱ().ˏ(i);
        if (ॱ().ˊ) {
            ॱ().ˊ = false;
            ॱ().ॱॱ();
            Logger.ˎ("SidProvider", "generateSidBackground, the sid : " + ˊ());
            if (z) {
                ॱ().ॱ("background", i);
            }
        }
    }

    public static void ˎ() {
        if (ॱ().ˎ.decrementAndGet() <= 0) {
            ॱ().ʼ();
            ॱ().ˊ = false;
            Logger.ˎ("SidProvider", "destroySidGenerator, the sid : " + ˊ());
        }
    }

    private void ˋ() {
        if (this.ॱ != null && this.ᐝ != null) {
            this.ॱ.postDelayed(this.ᐝ, 1800000);
        }
    }

    private void ʼ() {
        this.ˏ = 0;
        if (this.ॱ != null && this.ᐝ != null) {
            this.ॱ.removeCallbacks(this.ᐝ);
        }
    }

    private void ʻ() {
        this.ˏ = System.currentTimeMillis();
    }

    private void ॱॱ() {
        ʼ();
        ʻ();
        ˋ();
    }

    private void ˏ(int i) {
        this.ॱॱ = i;
    }
}
